﻿using System;
using System.Web.UI.WebControls;
using WorkOrder.Business;
using WorkOrder.Model;

namespace WorkOrder
{
    public partial class showOrder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            //{
            //    Session.Clear();
            //    ClientScript.RegisterClientScriptBlock(this.GetType(), "windowhref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.location.href='../login.aspx';</script>");
            //}
            refreshData();
        }

        #region 处理光标行颜色事件
        protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex >= 0)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor,this.style.background='#ffe3a0'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#fff'");
            }
        }
        #endregion

        private String HtmlCode(string TString)
        {
            if (TString != null)
            {
                TString = TString.Replace("\r", " <br/> ");
                TString = TString.Replace(" ", "&nbsp;");
                return TString;
            }
            return "空";
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            refreshData();
        }

        private void refreshData()
        {
            Business_Table_Work_order b_t_order = new Business_Table_Work_order();

            if (!string.IsNullOrEmpty(Request.Params["id"]))
            {
                hidID.Value = Request.Params["id"];
                Model_Table_Work_order model = b_t_order.GetData(Request.Params["id"]);
                try
                {
                    lblOrderNo.Text = model.Order_number;
                    if (!string.IsNullOrEmpty(model.Product_id) && model.Product_id!="0") lblProduct.Text = b_t_order.GetProductByID(model.Product_id).Product_name;
                    if (!string.IsNullOrEmpty(model.Order_type_id) && model.Order_type_id != "0") lblOrderType.Text = b_t_order.GetOrderTypeByID(model.Order_type_id).Order_type;
                    if (!string.IsNullOrEmpty(model.Area_id) && model.Area_id != "0") lblArea.Text = b_t_order.GetAreaByID(model.Area_id).Area_name;
                    if (!string.IsNullOrEmpty(model.Town_id) && model.Town_id != "0") lblTown.Text = b_t_order.GetTownByID(model.Town_id).Town_name;
                    lblTitle.Text = model.Title;
                    lblGroupCode.Text = model.GroupCode;
                    if (!string.IsNullOrEmpty(model.EntryPerson)) lblCreator.Text = b_t_order.GetUserByID(model.EntryPerson).Remark;
                    lblCreateTime.Text = model.CheckInTime.ToString();
                    lblModify_content.Text = model.OrderContent;
                    lblRemark.Text = model.Remark;
                    lblClustering_client.Text = model.ClusteringClient;
                    lblIsBack.Text = model.IsBack ? "是" : "否";
                    lblFinishTime.Text = model.FinishTime;
                    lblAnalysis_time.Text = model.Analysis_time;
                    lblAudit_time.Text = model.Audit_time;
                    lblConfig_time.Text = model.Config_time;
                    lblConfirm_time.Text = model.Confirm_time;
                    lblAccessMode.Text = model.AccessMode;
                    lblReasonComment.Text = model.BackReasonComment;
                    lblCustomerCode.Text = model.CustomerCode;
                    lblReasonType.Text = model.BackReason;
                    lblPtime.Text = model.TaskTime;

                    DataList1.DataSource = b_t_order.GetException(model.Order_id);
                    DataList1.DataBind();

                    GridView1.DataSource = b_t_order.GetOrderRecordByOrderID(hidID.Value);
                    GridView1.DataBind();
                }
                catch { }
            }
        }
    }
}
